<template>
    <!-- 
        页面以 QS （勤瘦） 为主命名
        每个页面再根据页面内容，添加不同命名后续 （如登录页 - loading）
        页面内命名都以本页面主题为开头，加功能后缀 如：loading-confirm-btn
        本页面主题:userInfo
     -->
    <div class="QS-content-template QS-userInfo">
        <div class="userInfo_search">
            <el-input class="search_input" clearable v-model="search_info" placeholder="请输入搜索关键字"></el-input>
            <el-button class="search_btn" type="primary">搜索</el-button>
        </div>
        
        <el-table
            class="userInfo_table"
            :data="tableData"
            style="width: 100%">
            <el-table-column type="expand">
                <template slot-scope="props">
                    <el-form label-position="left" inline class="demo-table-expand">
                        <el-form-item v-for="(item,index) in bodyDate" :key="index" :label="item.name">
                            <span>{{ props.row[item.key] }}</span>
                        </el-form-item>
                    </el-form>
                </template>
            </el-table-column>

            <el-table-column
                v-for="(item,index) in columns"
                :key="'columns'+index"
                :label="item.name"
                :prop="item.key">
            </el-table-column>
        </el-table>


        <div class="block block_pagenation">
            <!-- <span class="demonstration">直接前往</span> -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="currentPage"
                :page-size="10"
                layout="prev, pager, next, jumper"
                :total="totalNum">
            </el-pagination>
        </div>
    </div>
</template>

<script>

export default {
	components: {
	
	},
	data(){
		return {
            columns:[],//展示列表 table head展示项
            bodyDate:[],//所有展示用户信息列表，从返回数据中提取，并根据字段及字段含义对应手动添加
            currentPage:1,
            search_info:'',//搜索关键字
            tableData: [],
            totalNum:10,//数据总数
		}
    },
    mounted(){
        // for(var i = 0;i < 21;i ++){
        //     this.tableData.push(
        //         {
        //             id:'',//用户主键
        //             wechatName:'',//用户微信名称
        //             wechatOpenId:'',//用户微信唯一标识
        //             gender:'',//性别
        //             birthday:'',//出生日期
        //             height:'',//身高
        //             userType:'',//用户类型
        //             avatarUrl:'',//用户头像地址
        //             initialWeight:'',//初始体重
        //             currentWeight:'',//用户当前体重
        //             targetWeight:'',//用户目标体重
        //             cumulativeWeightLoss:'',//用户累计减重
        //             cumulativeWeightLossDirection:'',//累计减重方向,减-D,增-U
        //             compareLastWeightLossDirection:'',//较上次减重方向,减-D,增-U
        //             totalAccumulatedPunchTime:'',//用户总累计打卡天数
        //             compareLastWeightLoss:'',//比较上次减重
        //             totalPoints:'',//总积分
        //             gmtCreate:'',//创建时间
        //             gmtModifier:'',//修改时间
        //             continuousWeightRecording_7:'',//连续记录体重7天
        //             continuousWeightRecording_14:'',//连续记录体重14天
        //             continuousWeightRecording_21:'',//连续记录体重21天
        //             continuousWeightRecording_28:'',//连续记录体重28天
        //             continuousWeightRecording_35:'',//连续记录体重35天
        //             country:'',//国家
        //             province:'',//省
        //             city:'',//市
        //             sessionKey:'',//会话key
        //             accumulatedPunchTime:'',//最新连续打卡天数
        //         }
        //     );
        // }

        this.setbodyDate();
        this.getuserInfoData('0');
    },
    methods:{
        // this.$router.push('/GDPLHasReturned');
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.getuserInfoData(val);
        },
        getuserInfoData(page){
            this.$fetch("user/findlist",{
                page:page ? page.toString() : '0',//第几页
                size:'1',//每页大小
                Sort:'',//排序字段,方式
                userType:'1',//用户类型,1 代表用户
                // userId:sessionStorage.getItem("userId"),
            }).then(res=>{
                console.log(res)
                this.totalNum = Number(res.total);
                this.tableData.splice(0);
                for(var i = 0;i < res.rows.length;i ++){
                    this.tableData.push(
                        {
                            id:res.rows[i].id || '',//用户主键
                            wechatName:res.rows[i].wechatName || '',//用户微信名称
                            wechatOpenId:res.rows[i].wechatOpenId || '',//用户微信唯一标识
                            gender:res.rows[i].gender || '',//性别
                            birthday:this.$commonFunc.timestampToTime(res.rows[i].birthday) || '',//出生日期
                            height:res.rows[i].height || '',//身高
                            userType:res.rows[i].userType || '',//用户类型
                            avatarUrl:res.rows[i].avatarUrl || '',//用户头像地址
                            initialWeight:res.rows[i].initialWeight || '',//初始体重
                            currentWeight:res.rows[i].currentWeight || '',//用户当前体重
                            targetWeight:res.rows[i].targetWeight || '',//用户目标体重
                            cumulativeWeightLoss:res.rows[i].cumulativeWeightLoss || '',//用户累计减重
                            // cumulativeWeightLossDirection:'',//累计减重方向,减-D,增-U
                            // compareLastWeightLossDirection:'',//较上次减重方向,减-D,增-U
                            totalAccumulatedPunchTime:res.rows[i].totalAccumulatedPunchTime || '',//用户总累计打卡天数
                            compareLastWeightLoss:res.rows[i].compareLastWeightLoss || '',//比较上次减重
                            totalPoints:res.rows[i].totalPoints || '',//总积分
                            gmtCreate:this.$commonFunc.timestampToTime(res.rows[i].gmtCreate) || '',//创建时间
                            gmtModifier:this.$commonFunc.timestampToTime(res.rows[i].gmtModifier) || '',//修改时间
                            country:res.rows[i].country || '',//国家
                            province:res.rows[i].province || '',//省
                            city:res.rows[i].city || '',//市
                            sessionKey:res.rows[i].sessionKey || '',//会话key
                            accumulatedPunchTime:res.rows[i].accumulatedPunchTime || '',//最新连续打卡天数
                            continuousWeightRecording7:res.rows[i].continuousWeightRecording7 || '',//连续记录体重7天
                            continuousWeightRecording14:res.rows[i].continuousWeightRecording14 || '',//连续记录体重14天
                            continuousWeightRecording21:res.rows[i].continuousWeightRecording21 || '',//连续记录体重21天
                            continuousWeightRecording28:res.rows[i].continuousWeightRecording28 || '',//连续记录体重28天
                            continuousWeightRecording35:res.rows[i].continuousWeightRecording35 || '',//连续记录体重35天
                        }
                    );
                }
            })
        },
        setbodyDate(){
            this.columns = [//展示列表 table head展示项
                {key:'wechatName',name:'用户微信名称'},
                {key:'birthday',name:'出生日期'},
                {key:'gender',name:'性别'},
                {key:'height',name:'身高'},
                {key:'totalPoints',name:'总积分'},
                {key:'initialWeight',name:'用户当前体重'},
            ];

            this.bodyDate = [//所有展示用户信息列表，从返回数据中提取，并根据字段及字段含义对应手动添加
                {key:'wechatName',name:'用户微信名称'},
                {key:'gender',name:'性别'},
                {key:'birthday',name:'出生日期'},
                {key:'height',name:'身高'},
                {key:'totalPoints',name:'总积分'},
                {key:'currentWeight',name:'用户当前体重'},
                {key:'country',name:'国家'},
                {key:'province',name:'省'},
                {key:'city',name:'市'},
                {key:'initialWeight',name:'初始体重'},
                {key:'targetWeight',name:'用户目标体重'},
                {key:'cumulativeWeightLoss',name:'用户累计减重'},
                {key:'totalAccumulatedPunchTime',name:'用户总累计打卡天数'},
                {key:'gmtCreate',name:'创建时间'},
                {key:'gmtModifier',name:'修改时间'},
                {key:'continuousWeightRecording7',name:'连续记录体重7天'},
                {key:'continuousWeightRecording14',name:'连续记录体重14天'},
                {key:'continuousWeightRecording21',name:'连续记录体重21天'},
                {key:'continuousWeightRecording28',name:'连续记录体重28天'},
                {key:'continuousWeightRecording35',name:'连续记录体重35天'},
                {key:'accumulatedPunchTime',name:'最新连续打卡天数'}
            ];
        }
    }
}
</script>